<?php 
	require ("../connect/connect.php");
	include '../template/template_main.tpl';
	require 'anuncioCtrl.php';
	
	if(isset($_SESSION["profile"]) && !($_SESSION["profile"] == "2"))
		header("Location: ../index.php");
		
	$avisos = getAnuncios($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/template.css" />
<link rel="stylesheet" type="text/css" href="../css/corpo_main.css" />
<link rel="stylesheet" type="text/css" href="../css/form.css" />
<script type="text/javascript" src="../js/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="../js/main.js" ></script>
<script type="text/javascript" src="../js/forum.js" ></script>

<title>.:MateMatrix:.</title>
</head>
<body>
	<?php makeHeader(); ?>
	<?php echo $estruturaInicio;?>
	<h1>- Lista de Epocas -</h1>
	<?php
		echo '<div id="forum_corpo"><table id="forum_tabela" border=1><tr id="forum_header"><th class="lstAnunc_assunto">Assunto</th><th class="lstAnunc_eNome">Nome Epoca</th><th class="lstAnunc_aNome">Nome Autor</th><th class="forum_data">Data Inicio</th><th class="forum_data">Data Fim</th><th class="lstEpocas_editar">Editar</th></tr>';
		
		if ($avisos->num_rows > 0)
		{
			/**
			 * $row[0] = `av`.`id`				 $_POST['idAnuncio']
			 * $row[1] = `ad`.`nome`		<---
			 * $row[2] = `av`.`id_epoca`		 $_POST['idEpoca']
			 * $row[3] = `ep`.`nome`		<---
			 * $row[4] = `av`.`assunto`		<--- $_POST['assunto']
			 * $row[5] = `av`.`texto`		<<-- $_POST['texto']
			 * $row[6] = `av`.`data_ini`	<--- $_POST['data_ini']
			 * $row[7] = `av`.`data_fim`	<--- $_POST['data_fim']
			 */
			$i = 0;
			
			while ($row = $avisos->fetch_row())
			{
				$class = "";
				if (($i%2) == 1)
					$class = "forum_odd_row";
				
				$inputs = "<form action=\"editAnuncio.php\" method=\"post\">";
				$inputs = $inputs . "<input type=\"hidden\" name=\"idAnuncio\" value=\"$row[0]\"/>";
				$inputs = $inputs . "<input type=\"hidden\" name=\"idEpoca\" value=\"$row[2]\"/>";
				$inputs = $inputs . "<input type=\"hidden\" name=\"assunto\" value=\"".htmlspecialchars(iconv("windows-1252", "utf-8", $row[4]))."\"/>";
				$inputs = $inputs . "<input type=\"hidden\" name=\"texto\" value=\"".htmlspecialchars(iconv("windows-1252", "utf-8", $row[5]))."\"/>";
				$inputs = $inputs . "<input type=\"hidden\" name=\"data_ini\" value=\"$row[6]\"/>";
				$inputs = $inputs . "<input type=\"hidden\" name=\"data_fim\" value=\"$row[7]\"/>";
				$inputs = $inputs . "<input type=\"submit\" value=\"Editar\"/></form>";
				
				printf("<tr id=\"%s\" class=\"$class\"><td class=\"lstAnunc_assunto\"><a onclick=\"mudarMostrar('%s')\" title=\"Texto\">%s</a></td><td class=\"lstAnunc_eNome\">%s</td><td class=\"lstAnunc_aNome\">%s</td><td class=\"forum_data\">$row[6]</td><td class=\"forum_data\">$row[7]</td><td class=\"lstEpocas_editar\">$inputs</td></tr>", iconv("windows-1252","utf-8",$row[0]), iconv("windows-1252","utf-8",$row[0]), htmlspecialchars(iconv("windows-1252","utf-8",$row[4])), htmlspecialchars(iconv("windows-1252","utf-8",$row[3])), htmlspecialchars(iconv("windows-1252","utf-8",$row[1])));
				printf("<tr id=\"msg_%s\" class=\"esconder\"><td colspan=\"6\"><pre class=\"forum_mensagens\">%s</pre>", iconv("windows-1252","utf-8",$row[0]), htmlspecialchars(iconv("windows-1252","utf-8", $row[5])));
				$i++;
			}
		}
		else 
			echo '<tr><td colspan="7" id="forum_semMsg">Não existem anuncios registadas</td></tr>';
		echo '</table></div>';
		
		echo $estruturaFim;
	?>
	<?php echo $footer;?>
</body>
</html>